<link rel="stylesheet" type="text/css" href="../stylesheet/style.css"/>
<?php
/*
* @author Nguyen Xuan Hong
* @copyright 2011
*/

require_once('../includes/menu.tbl.php');

$branch_id = $_GET['branch'];
	
if($_GET['mode'] == 'listmenu')
{
	$pClsMenu = new clsMenuTable();	
	if($pClsMenu->avaibleSubmit()){
		$pClsMenu->loadBuffer();
		$pClsMenu->setvalue('branch_id', $branch_id);
		$attachfile = upload_file("Upload/", 'videobrowser_attach', $pClsMenu->value('attach'));
		if($attachfile != "")
		{
			$pClsMenu->setvalue('attach', $attachfile);
		} 
		$pClsMenu->insertDB();
		echo acpredirect();
		exit();
	}
	echo $pClsMenu->createForm('Thêm thực đơn');
	
	require_once('../includes/templates.php');
	$table = new clsTable('lstmenu',array(array("ID", "1"),array("Tên thực đơn", 0),array("Sửa", 1),array("Xóa", 1)));
	$list_menu = $pClsMenu->listobj($branch_id);
	foreach($list_menu as $menu){
		$html_remove =      '<a href="?page=menu&mode=deletemenu&branch='.$branch_id.'&id='.$menu->value('id').'">Xóa</a>';
		$html_edit = 	'<a href="?page=menu&mode=editmenu&branch='.$branch_id.'&id='.$menu->value('id').'">Sửa</a>';	
		$table->addRow($menu->value('id'),array($menu->value('id'),$menu->value('title'), $html_edit,$html_remove));
	}
	echo $table->putHTML(true);
	exit();
}

if($_GET['mode'] == 'deletemenu'){		
	// Redefine insert
	$deleteid = sget('id');			
	$pClsMenu = new clsMenuTable($deleteid);
	if(!$_POST['submit']){
		?>
        
	<center><div class="notification warning">
        <span></span>
        <p><strong>Warning!</strong> 
        	<div class="text">Bạn có muốn xóa Thực đơn này không</div> 
            <div class="btn"><form method='post'><input type='submit' name='submit' value = 'Xóa' /></form></div>
         </p>
	</div></center>
        <?
		exit();
	}
	delete_file($pClsMenu->value('attach'));
	$pClsMenu->removeDB('id', $deleteid);
    echo acpredirect('page=menu&mode=listmenu&branch='.$branch_id);
	exit();
}

if($_GET['mode'] == 'editmenu')
{
	$edit = (int)sget('id');
	$pClsMenu = new clsMenuTable($deleteid);
	if($pClsMenu->avaibleSubmit()){
		$pClsMenu->loadBuffer();
		$attachfile = upload_file("Upload/", 'videobrowser_attach', $pClsMenu->value('attach'));
		if($attachfile != "")
		{
			$pClsMenu->setvalue('attach', $attachfile);
		} 
		$pClsMenu->updateDB('id',$edit);
        echo acpredirect('page=menu&mode=listmenu&branch='.$branch_id);
		exit();
	}
	$pClsMenu->loadDB('id',$edit);
       echo $pClsMenu->createForm('Sửa thực đơn');
	exit();
}
?> 
